import axios from 'axios';
import qs from 'qs';
const request = axios.create({
  baseURL: 'http://47.106.115.187:8088/',
});
//请求拦截器
request.interceptors.request.use(
  function (config) {   
    if(config.url === '/api/signup/add' ){
      //如果是get请求，且params是数组类型如arr=[1,2]，则转换成arr=1&arr=2
      config.paramsSerializer = function(params) {
          return qs.stringify(params, {arrayFormat: 'repeat'})
      }
    }

    //请求发送会经过
    const token = localStorage.getItem('token');
    if(token){
  
      config.headers.Authorization = token;
      config.headers['token'] = token;
    
  }
      
    return config;
  },
  function (err) {
    return Promise.reject(err);
  }
);

export default request;
